import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    count: 0,
    emptyCellsPos: [],
    fillResArr: []
  },
  mutations: {
    increment(state) {
      state.count++
    },

    updateFillResArr(state, payload) {
      // console.log(arguments);
      const payloadIndex = payload.index;

      let indexes = [];
      if (Array.isArray(payloadIndex)) {
        indexes = payloadIndex;
      } else if (typeof (payloadIndex) === 'number') {
        indexes.push(payloadIndex);
      }

      indexes.forEach(index => {
        state.fillResArr[index] = payload.data;
      })
    },

    updateEmptyCellsPos(state, payload) {
      state.emptyCellsPos = payload;
    }
  }
})

export default store;